Add a way to force a unit of work to always be rebuilt
authorNick Cameron <ncameron@mozilla.com>
Mon, 10 Jul 2017 02:09:56 +0000 (14:09 +1200)
committerNick Cameron <ncameron@mozilla.com>
Mon, 10 Jul 2017 02:09:56 +0000 (14:09 +1200)
src/cargo/ops/cargo_rustc/mod.rs

index 6e83c04a9bd3aebdfa55a55b68d58b89c3653c43..34601913ac7a799fb48dc16c502fc12baa133809 100644 (file)
@@ -83,6 +83,12 @@ pub trait Executor: Send + Sync + 'static {
         cmd.exec_with_streaming(handle_stdout, handle_stderr, false)?;
         Ok(())
     }
+
+    /// Queried when queuing each unit of work. If it returns true, then the
+    /// unit will always be rebuilt, independent of whether it needs to be.
+    fn force_rebuild(&self, _unit: &Unit) -> bool {
+        false
+    }
 }
 
 /// A DefaultExecutor calls rustc without doing anything else. It is Cargo's
@@ -230,7 +236,7 @@ fn compile<'a, 'cfg: 'a>(cx: &mut Context<'a, 'cfg>,
         // we run these targets later, so this is just a noop for now
         (Work::new(|_| Ok(())), Work::new(|_| Ok(())), Freshness::Fresh)
     } else {
-        let (freshness, dirty, fresh) = fingerprint::prepare_target(cx, unit)?;
+        let (mut freshness, dirty, fresh) = fingerprint::prepare_target(cx, unit)?;
         let work = if unit.profile.doc {
             rustdoc(cx, unit)?
         } else {
@@ -239,6 +245,11 @@ fn compile<'a, 'cfg: 'a>(cx: &mut Context<'a, 'cfg>,
         // Need to link targets on both the dirty and fresh
         let dirty = work.then(link_targets(cx, unit, false)?).then(dirty);
         let fresh = link_targets(cx, unit, true)?.then(fresh);
+
+        if exec.force_rebuild(unit) {
+            freshness = Freshness::Dirty;
+        }
+
         (dirty, fresh, freshness)
     };
     jobs.enqueue(cx, unit, Job::new(dirty, fresh), freshness)?;